]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
status/network: Add activate() to NMDeviceItem
authorFlorian Müllner <fmuellner@gnome.org>
Wed, 3 Aug 2022 04:44:36 +0000 (06:44 +0200)
committerMarge Bot <marge-bot@gnome.org>
Wed, 10 Aug 2022 16:37:15 +0000 (16:37 +0000)
DeviceItems are sections, and therefore not actually activatable.

However when we port to quick settings, those toggles will need
to do *something*.

For that reason, provide an activate() implementation that

 1. deactivates the device if currently connected

 2. delegates the action to the most-recently used item,
    the first visible item or the auto-connect item (in that
    order)

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2408>

js/ui/status/network.js

index 39a89e93d2f8561f4af04bff27e0df8caaeb4be6..1beab28c1f3ad1056be0c2cb973ab85dfddf3c0c 100644 (file)
@@ -499,6 +499,29 @@ const NMDeviceItem = GObject.registerClass({
             this._addConnection(conn);
     }
 
+    _getActivatableItem() {
+        const [lastUsed] = this._itemSorter.itemsByMru();
+        if (lastUsed?.timestamp > 0)
+            return lastUsed;
+
+        const [firstItem] = this._itemSorter;
+        if (firstItem)
+            return firstItem;
+
+        console.assert(this._autoConnectItem.visible,
+            `${this}'s autoConnect item should be visible when otherwise empty`);
+        return this._autoConnectItem;
+    }
+
+    activate() {
+        super.activate();
+
+        if (this._activeConnection)
+            this.deactivateConnection();
+        else
+            this._getActivatableItem()?.activate();
+    }
+
     activateConnection(connection) {
         this._client.activate_connection_async(connection, this._device, null, null, null);
     }